import Vue from 'vue'
import VueRouter from 'vue-router'
import ViewUI from 'view-design'

Vue.use(ViewUI)
Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Home',
    meta: { title: "首页" },
    component: () =>
        import ('../views/Home')
}, {
    path: '*',
    meta: { title: "404-页面不存在" },
    // 路由懒加载
    component: () =>
        import ('@/views/Error/E404')
}]

const router = new VueRouter({
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
    if (to.path == '/') {
        sessionStorage.clear()
    }
    ViewUI.LoadingBar.start()
    next()
})

router.afterEach(() => {
    ViewUI.LoadingBar.finish()
})

export default router